/* Tests for password.c
 *
 * Copyright 2008 Cian Synnott.
 * 
 * $Id: password_test.c 19 2009-11-27 20:46:48Z cian $
 */
#include <stdio.h>
#include <termios.h>

#include "cutest/CuTest.h"
#include "password.h"

/* get_password is just a wrapper around getline, so we test toggle only */
void TestToggleEcho(CuTest *tc) {
  struct termios terminal;

  tcgetattr(0, &terminal);
  CuAssertTrue(tc, terminal.c_lflag & ECHO);

  toggle_echo();

  tcgetattr(0, &terminal);
  CuAssertTrue(tc, (terminal.c_lflag & ECHO) == 0);

  toggle_echo();

  tcgetattr(0, &terminal);
  CuAssertTrue(tc, terminal.c_lflag & ECHO);
}

int main(void) {
  CuString *output = CuStringNew();
  CuSuite* suite = CuSuiteNew();

  SUITE_ADD_TEST(suite, TestToggleEcho);

  CuSuiteRun(suite);
  CuSuiteSummary(suite, output);
  CuSuiteDetails(suite, output);
  printf("%s\n", output->buffer);

  return 0;
}
